<% content_for :maps do %>

<% if RAILS_ENV == "production" %>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAuunGS_VtjHf9ymsKEjhoRBSSHSGZ60oIcyQqQJfOT05d_h2_CRT3d7pEbT2gfxLvx0ac1yBom78f-w" type="text/javascript"></script>
<% else %>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAuunGS_VtjHf9ymsKEjhoRBTJQa0g3IQ9GZqIMmInSLzwtGDKaBSkf_JiFVsob6gVhskLQRN0LYystw" type="text/javascript"></script>
<% end %>

<script type="text/javascript">
    //<![CDATA[
    var mm = [];
    function load() {
      if (GBrowserIsCompatible()) {

        for(i=0; i<mm.length; i++) {
          add_map(mm[i])
        }

      }
    }


    function add_map(arr) {
      var ps = arr[1].split(",")
      var map = new GMap2(document.getElementById(arr[0]));
      var center = new GLatLng(ps[0], ps[1]);
      map.setCenter(center, 12);
      var marker = new GMarker(center);
      map.addOverlay(marker);

    }
    window.onload = load;

    //]]>
</script>

<% end %>

<ul id="msg_list">
  <% @messages.each do |message| %>
    <li>
      <% if message.has_position? %>
        <script type="text/javascript" charset="utf-8">
          mm.push(["map_<%= message.id %>", "<%= message.position %>"])
        </script>
        
        <div id="map_<%= message.id %>" class="messagemap" style="width:240px; height:80px">
        </div>
      <% end %>
      <div class="message">
        <%= simple_format message.message %>
      </div>
      <p class="date">Enviado el <%= message.created_at %></p>
    </li>
  <% end%>
</ul>
<%= will_paginate @messages %>